package com.cat.dynamicPlanning;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/solving-questions-with-brainpower/description/
 * @create 2025/8/28 18:42
 * @since JDK17
 */

public class Solution17 {
    public long mostPoints(int[][] questions) {
        int n = questions.length;
        long[] dp = new long[n];
//        long ans = 0;
        dp[n - 1] = questions[n - 1][0];
        for (int i = n - 2, j, k; i >= 0; i--) {
            k = i + questions[i][1] + 1;
            dp[i] = questions[i][0] + (k < n ? dp[k] : 0);
            dp[i] = Math.max(dp[i], dp[i + 1]);
        }
        return dp[0];
    }
}
